package com.aric.springbootmusic.mapper;

import com.aric.springbootmusic.entity.pojo.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    @Results(id="baseAuthor",value = {
            @Result(id = true,column = "ps_id",property = "psId"),
            @Result(column = "ps_cname",property = "psCname")
    })
    @Select(value = """
         select
        	ps_id,
        	ps_cname
         from
        	permission
         WHERE
            permission.ps_pid=#{psPid}	   
    """)
    List<Permission> selectThreeLevelPermission(Integer psPid);

    @Results(value = {
            @Result(id = true,column = "ps_id",property = "psId"),
            @Result(column = "ps_cname",property = "psCname"),
            @Result(column = "ps_id",property = "children",many=@Many(select="com.aric.springbootmusic.mapper.PermissionMapper.selectThreeLevelPermission"))
    })
    @Select(value = """
         select
        	ps_id,
        	ps_cname
         from
        	permission
         WHERE
            permission.ps_pid=#{psPid}	   
    """)
    List<Permission> selectSecondLevelPermission(Integer psPid);

    @Results(value = {
        @Result(id = true,column = "ps_id",property = "psId"),
        @Result(column = "ps_cname",property = "psCname"),
        @Result(column = "ps_id",property = "children",many=@Many(select="com.aric.springbootmusic.mapper.PermissionMapper.selectSecondLevelPermission"))
    })
    @Select("""
        select
        	ps_id,
        	ps_cname
        from
        	permission
        WHERE
            permission.ps_level=0	
    """)
    List<Permission> selectAllPermission();

    @Select("""
        select
              ps_id as id
        from
            rp
        WHERE
            rp.role_id=#{id}  
    """)
    List<Integer> selectRoleAuthor(Integer id);
}
